package logger

import (
	"bufio"
	"example/pkg/except"
	"io"
	"os"
	"time"
)

type Reader interface {
	Read(rc chan string)
}


type logger struct {
	path string
}

func (l logger) Read(rc chan string)  {
	fp, err := os.Open(l.path)
	except.CheckError(err)

	_, _ = fp.Seek(0, 2)
    rd := bufio.NewReader(fp)

    for {
		line,err := rd.ReadBytes('\n')
		if err == io.EOF {
			time.Sleep(time.Millisecond * 500)
			continue
		}
		except.CheckError(err)

		rc <- string(line[:len(line)-1])
	}

}
